﻿package org.hsl.avm2.translation.mouse;
import flash.events.MouseEvent;
import org.hsl.haxe.translation.ITranslator;
import org.hsl.haxe.translation.NativeEvent;
/**
 * A translator that translates mouse events to local mouse locations. The local mouse locations are the locations of the mouse
 * at the moment the mouse events were dispatched, relative to the object that dispatched them.
 */
// Ideally, the following line would be:
// class MouseLocationTranslater implements ITranslator<LocalMouseLocation> {
// However, that doesn't work targetingAVM2.
class MouseLocationTranslator<D> implements ITranslator<D> {
	/**
	 * Creates a new mouse location translator.
	 */
	public function new():Void {
	}
	public function translate(nativeEvent:NativeEvent):D {
		var mouseEvent:MouseEvent;
		try {
			mouseEvent = cast(nativeEvent, MouseEvent);
		} catch (error:Dynamic) {
			throw "The nativeEvent argument must be a MouseEvent.";
		}
		return untyped new LocalMouseLocation(mouseEvent.localX, mouseEvent.localY, mouseEvent.target);
	}
}